package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dto.WmSensitivePageRepDto;
import com.heima.model.wemedia.entity.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/sensitive")
public class WmSensitiveController {

    @Resource
    private WmSensitiveService wmSensitiveService;

    /**
     * 新增敏感词
     *
     * @param wmSensitive
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive) {
        return wmSensitiveService.save(wmSensitive);
    }

    /**
     * 敏感词列表展示
     *
     * @param dto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody WmSensitivePageRepDto dto) {
        return wmSensitiveService.list(dto);
    }

    /**
     * 敏感词修改
     *
     * @param wmSensitive
     * @return
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive) {
        wmSensitiveService.update(wmSensitive);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 敏感词删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("del/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        wmSensitiveService.deleteById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
